#include <flyweight_pattern.h>
#include<iostream>

FlyCircle::FlyCircle(string color)
{
    this->color = color;
}

void FlyCircle::draw()
{
    cout << "Circle: Draw() [Color : " + this->color << ", x : " << to_string(this->x) << ", y : " << to_string(this->y) << ", radius : " << to_string(this->radius) << endl;
}

void FlyCircle::setX(int x)
{
    this->x = x;
}

void FlyCircle::setY(int y)
{
    this->y = y;
}

void FlyCircle::setRadius(int radius)
{
    this->radius = radius;
}

FlyShapeFactory::~FlyShapeFactory()
{
    for (auto it = circleMap.begin(); it != circleMap.end(); it++)
    {
        delete it->second;
    }
    circleMap.clear();
}

FlyShape* FlyShapeFactory::getCircle(string color)
{
    if ( circleMap.find( color ) != circleMap.end())
    {
        return circleMap[color];
    }
    FlyShape* circle = new FlyCircle(color);
    circleMap.insert( map<string, FlyShape*>::value_type(color, circle));
    cout << "Creating circle of color : " << color << endl;
    return circle;
}
